from ccpm.pmbase import PluginBase
from ccpm.glan import Lan
import os
from ccpm.constants import Constant
import sys
import shutil


def fmt_verstr(verstr):
    nums = verstr[1:].split(".")
    return int(nums[0]) * 100 + int(nums[1]) * 10 + int(nums[2])


class UnInstallPlugin(PluginBase):

    PLUGIN_INFO = dict(
        name="uninstall",
        help="uninstall cocos package!"
    )

    def __init__(self):
        if not hasattr(self, "_inc"):
            self._inc = super().__init__(self.PLUGIN_INFO)
        return self._inc

    def __get_plugindir(self, pluginname, isglobal=False):
        # todo global install
        pdir = os.path.join(os.getcwd(), Constant.L_PACKINSTALL_DIR)
        return os.path.join(pdir, pluginname)

    def parser_config(self, argparser):
        super().parser_config(argparser)
        argparser.add_argument("pluginname",
                               help="the plugin name to install")
        argparser.add_argument("-g", dest="isglobalins",
                               help="global install the modules")

    def run(self, argpars):
        super().run(argpars)
        isglobalins = argpars.isglobalins
        pluginname = argpars.pluginname
        inspath = self.__get_plugindir(pluginname, isglobalins)
        shutil.rmtree(inspath)
        # install mainplugin


__all__ = [
    "UnInstallPlugin"
]
